package com.lxr0860.lxr0860production_test.utils;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.Window;


import com.lxr0860.lxr0860production_test.R;
import com.lxr0860.lxr0860production_test.view.CommonDialog;
import com.lxr0860.lxr0860production_test.view.CustomDialog;

import java.io.File;

/**
 * Created by 11 on 2018/2/1.
 */

public class Contants {
    public static final String WIFI_NAME = "UNIRIHO";
    public static final String WIFI_PWD = "uniriho03";
    public static String ZZCJ = "ZZCJ";
    public static String ZDCS = "ZDCS";
    public static String FSCS = "FSCS";
    public static String DWCS = "DWCS";
    public static String GWCS = "GWCS";
    public static String CPJY = "CPJY";
    public static String CPCJ = "CPCJ";
    public static String UpdateDEVInfoState = "UpdateDEVInfoState";

    public static int ItemTestState_Fail = 2;
    public static int ItemTestState_NOTest = 1;
    public static int ItemTestState_Success = 0;
    public static String TestState = "fail";

    public static final String LOG_TAG = "lxr_5002";
    public static boolean istrue = false;
    public static final String LOGCAT_APP = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "Logcat_app" + File.separator;

    public static final String LOGCAT_CRASHINFO = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "crash_logInfo" + File.separator;
    public static final String LOG_TESTRECORD_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + File.separator + "testRecord";
    public static final int DIALOG_POSITIVE = 0x10;
    public static final int DIALOG_NEGATIVE = 0x11;
    public static final int STRENGTH_USB = 0;
    public static final int STRENGTH_IC = 1;
    public static final int STRENGTH_KEY = 2;
    public static final int STRENGTH_RECORD = 3;

    public static final String PHOTO_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + File.separator + "takePhotos";
    public static final String LOG_FACTORY_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + File.separator + "lxr5002";
    public static final String LOG_STRENGTH_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + File.separator + "strength.txt";
    public static final String LOG_DIWEN_DELAY_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + File.separator + "diwen_delay.txt";
    public static String[] itemTitles = {"设备信息", "LCD", "TP", "按键", "4G",
            "IC卡", "扫描", "音频", "TF卡", "USB", "闪光灯", "后置摄像", "前置摄像",
            "蓝牙", "GPS", "WIFI", "麦克风", "光线感应", "串口通信", "起爆板", "LED", "马达"};

    /**
     * "听筒", "距离感应", "重力传感","非接", "UHF", "指纹", "系统",
     *
     */
    public static String[] itemTitlesTest = {"SBXX", "LCD", "TP", "AJ", "4G",
            "IC", "SM", "YP", "TF", "USB", "SGD", "HZSXT", "QZSXT",
            "LY", "GPS", "WIFI", "TT", "MKF", "GXGY", "JLGY", "ZLGY",
            "NFC", "UHF", "ZW", "XT", "CKTX", "QBB", "LED", "MD"};

    public static String[] infoTitlesTest = {"BarcodeModuleModel", "BtMac", "WifiMac", "DetonatorNo", "EquipmentModel", "FlashID", "FrontCameraModel",
            "IMEI", "LCDScreenModel", "MCUVS", "RearCameraModel", "SamNo", "SerialNo", "SystemVersion", "TerminalNo", "TestSoftVS", "TouchScreenModel",
            "UpdateDate"};
    public static String[] configs = {"马达","按键", "麦克风","光线感应", "串口通信", "起爆板", "LED","闪光灯"
            ,"扫描"};

    public static String getStrengthType(int option) {
        String type = null;
        switch (option) {
            case Contants.STRENGTH_USB:
                type = "USB强化测试";
                break;
            case Contants.STRENGTH_IC:
                type = "IC卡强化测试";
                break;
            case Contants.STRENGTH_KEY:
                type = "按键强化测试";
                break;
            case Contants.STRENGTH_RECORD:
                type = "测试记录";
                break;
        }
        return type;
    }

    public static final int TEST_ZUZHUANG = 0;
    public static final int TEST_ZHENDONG = 1;
    public static final int TEST_DIWEN = 3;
    public static final int TEST_GAOWEN = 4;
    public static final int TEST_FANGSHUI = 2;
    public static final int TEST_CHENGPIN = 5;
    public static final int TEST_CPCJ = 6;
    public static final int TEST_LAOHUA = 7;
    public static final int TEST_QIANGHUA = 8;
    public static final int TEST_JILU = 9;
    public static final int TEST_CHECK = 10;
    public static final int TEST_CODEBINDING = 11;
//    public static final int TEST_SETNUMBER = 12;



    public static final int TEST_ITEM_INFO = 0;
    public static final int TEST_ITEM_LCD = 1;
    public static final int TEST_ITEM_TP = 2;
    public static final int TEST_ITEM_KEY = 3;
    public static final int TEST_ITEM_GPRS = 4;
    public static final int TEST_ITEM_IC = 5;
    public static final int TEST_ITEM_SCAN = 6;
    public static final int TEST_ITEM_AUDIO = 7;
    public static final int TEST_ITEM_TF = 8;
    public static final int TEST_ITEM_USB = 9;
    public static final int TEST_ITEM_FLASH = 10;
    public static final int TEST_ITEM_CAMERA = 11;
    public static final int TEST_FONT_CAMERA = 12;
    public static final int TEST_ITEM_BLUETOOTH = 13;
    public static final int TEST_ITEM_GPS = 14;

    public static final int TEST_ITEM_WIFI = 15;
    public static final int TEST_ITEM_MIC = 16;
    public static final int TEST_ITEM_LIGHT_SENSOR = 17;
    public static final int TEST_ITEM_POINT = 18;
    public static final int TEST_ITEM_PCIE = 19;
    public static final int TEST_ITEM_LED = 20;
    public static final int TEST_ITEM_ZD = 21;
    public static final int TEST_ITEM_YT = 22;

    //    public static final int TEST_ITEM_PROXIMITY_SENSOR = 19;
    public static final int TEST_ITEM_ACCELEROMETER = 20;
//    public static final int TEST_ITEM_NFC = 21;
//    public static final int TEST_ITEM_UHF = 22;
//    public static final int TEST_ITEM_FINGER = 23;
//    public static final int TEST_ITEM_SYSTEM = 24;
        public static final int TEST_ITEM_PHONE = 16;

    public static String getTopTitle(int option) {
        String title = null;
        switch (option) {
            case Contants.TEST_ZUZHUANG:
                title = "组装初检";
                break;
            case Contants.TEST_ZHENDONG:
                title = "振动测试";
                break;
            case Contants.TEST_DIWEN:
                title = "低温测试";
                break;
            case Contants.TEST_GAOWEN:
                title = "高温测试";
                break;
            case Contants.TEST_CHENGPIN:
                title = "成品检验";
                break;
            case Contants.TEST_LAOHUA:
                title = "老化测试";
                break;
            case Contants.TEST_FANGSHUI:
                title = "防水测试";
                break;
            case Contants.TEST_QIANGHUA:
                title = "强化测试";
                break;
            case Contants.TEST_JILU:
                title = "测试记录";
                break;
            case Contants.TEST_CHECK:
                title = "信息校对";
                break;
            case Contants.TEST_CODEBINDING:
                title = "记录上传";
                break;
            case Contants.TEST_CPCJ:
                title = "成品抽检";
                break;
//            case Contants.TEST_SETNUMBER:
//                title = "编号设置";
//                break;
        }
        return title;
    }

    public static int getItemBtnBgId(int option) {
        int btn_bg_id = R.drawable.selector_info;
        switch (option) {
            case Contants.TEST_ITEM_INFO:
                btn_bg_id = R.drawable.selector_info;
                break;
            case Contants.TEST_ITEM_LCD:
                btn_bg_id = R.drawable.selector_lcd;
                break;
            case Contants.TEST_ITEM_TP:
                btn_bg_id = R.drawable.selector_tp;
                break;
            case Contants.TEST_ITEM_KEY:
                btn_bg_id = R.drawable.selector_key;
                break;
            case Contants.TEST_ITEM_WIFI:
                btn_bg_id = R.drawable.selector_wifi;
                break;
            case Contants.TEST_ITEM_IC:
                btn_bg_id = R.drawable.selector_ic;
                break;
            case Contants.TEST_ITEM_SCAN:
                btn_bg_id = R.drawable.selector_scan;
                break;
            case Contants.TEST_ITEM_BLUETOOTH:
                btn_bg_id = R.drawable.selector_bluetooth;
                break;
            case Contants.TEST_ITEM_AUDIO:
                btn_bg_id = R.drawable.selector_audio;
                break;
            case Contants.TEST_ITEM_TF:
                btn_bg_id = R.drawable.selector_tf;
                break;
            case Contants.TEST_ITEM_USB:
                btn_bg_id = R.drawable.selector_usb;
                break;
            case Contants.TEST_ITEM_FLASH:
                btn_bg_id = R.drawable.selector_flash;
                break;
            case Contants.TEST_ITEM_CAMERA:
                btn_bg_id = R.drawable.selector_camera;
                break;
            case Contants.TEST_ITEM_GPRS:
                btn_bg_id = R.drawable.selector_gprs;
                break;
//            case Contants.TEST_ITEM_FINGER:
//                btn_bg_id = R.drawable.selector_finger;
//                break;
            case Contants.TEST_ITEM_GPS:
                btn_bg_id = R.drawable.selector_gps;
                break;
//            case Contants.TEST_ITEM_NFC:
//                btn_bg_id = R.drawable.selector_nfc;
//                break;
//            case Contants.TEST_ITEM_SYSTEM:
//                btn_bg_id = R.drawable.selector_system;
//                break;
//            case Contants.TEST_ITEM_UHF:
//                btn_bg_id = R.drawable.selector_uhf;
//                break;
            case Contants.TEST_ITEM_LIGHT_SENSOR:
                btn_bg_id = R.drawable.selector_light_sensor;
                break;
//            case Contants.TEST_ITEM_PROXIMITY_SENSOR:
//                btn_bg_id = R.drawable.selector_proximity;
//                break;
//            case Contants.TEST_ITEM_ACCELEROMETER:
//                btn_bg_id = R.drawable.selector_accelerometer;
//                break;
            case Contants.TEST_FONT_CAMERA:
                btn_bg_id = R.drawable.selector_camera;
                break;
//            case Contants.TEST_ITEM_PHONE:
//                btn_bg_id = R.drawable.selector_phone;
//                break;
            case Contants.TEST_ITEM_MIC:
                btn_bg_id = R.drawable.selector_mic;
                break;
            case Contants.TEST_ITEM_PCIE:
                btn_bg_id = R.drawable.selector_qudongqi;
                break;
            case Contants.TEST_ITEM_LED:
                btn_bg_id = R.drawable.selector_led;
                break;
            case Contants.TEST_ITEM_ZD:
                btn_bg_id = R.drawable.selector_zhendong;
                break;
            case Contants.TEST_ITEM_POINT:
                btn_bg_id = R.drawable.selector_piont;
                break;
//            case Contants.TEST_ITEM_YT:
//                btn_bg_id = R.drawable.selector_yitaiwang;
//                break;
        }
        return btn_bg_id;
    }

    public static CustomDialog.Builder showDailog(Context context, String msg, final Handler handler, int gravity) {
        CustomDialog.Builder builder = new CustomDialog.Builder(context, false);
        builder.setMessage(msg);
//        builder.setTitle("测试完毕");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                handler.sendEmptyMessage(Contants.DIALOG_POSITIVE);
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消",
                (dialog, which) -> {
                    handler.sendEmptyMessage(Contants.DIALOG_NEGATIVE);
                    dialog.dismiss();
                });
        CustomDialog dialog = builder.create();
        Window window = dialog.getWindow();
//        WindowManager.LayoutParams attributes = window.getAttributes();
        window.setGravity(gravity);
//        attributes.alpha = 0.6f;
//        window.setAttributes(attributes);
        dialog.show();
        return builder;
    }

    /**
     * 方法描述:[通用结果Dialog]
     *
     * @param activity 上下文
     * @param tag      模块标识
     * @param title    标题
     * @param msg      内容
     * @author: LXR-zsm
     * @Date: 2023/9/6
     * @Return: void
     */
    public static void showCommonDialog(Activity activity, int tag, String title, String msg) {
        showCommonDialog(activity,tag,title,msg,true);
    }
    public static void showCommonDialog(Activity activity, int tag, String title, String msg, boolean resultNormal) {
        new CommonDialog(activity, title, msg,resultNormal, new CommonDialog.BtnClickListener() {
            @Override
            public void onPositiveClickListener() {
                Intent mIntent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putBoolean("result", true);
                mIntent.putExtras(bundle);
                activity.setResult(tag, mIntent);
                activity.finish();
            }

            @Override
            public void onNegativeClickListener(boolean isFinish) {
                if (isFinish)
                    activity.finish();
            }
        }).show();
    }
    /**
     * 判断是否存在相机
     *
     * @param context
     * @return
     */
    public static boolean hasCamera(Context context) {
        PackageManager manager = context.getPackageManager();
        return manager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
                || manager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
    }
}
